package com.fallsvc.re.networkprogramming.JUC;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @auther falls_vc
 * description:
 * @date 2025/11/1  10:20
 */
public class CallableFutureTask {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int sum = 0;
                for (int i = 0; i < 100; i++) {
                    sum +=i;
                }
                return sum;
            }
        };

        Callable<Integer> callable1 = () -> {
            int sum = 0;
            for (int i = 0; i < 101; i++) {
                sum +=i;
            }
            return sum;
        };
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        Thread thread  = new Thread(futureTask);
        thread.start();

        int ret = futureTask.get();
        System.out.println(ret);
    }
}
